// pages/register/register.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // input内容
    userPhone: '',
    password: '',
    userConfirmPasword: '',
  },
  checkForm: function (e) {
    var that = this
    console.log(e)
    var userPhone = e.detail.value.userPhone
    var password = e.detail.value.password
    var userConfirmPasword = e.detail.value.userConfirmPasword
    console.log(userPhone, password, userConfirmPasword)
    var pattern = /^1[3456789]\d{9}$/ //手机号要符合规范
    var pattern2 = /^\w{4,8}$/ //密码要在4-8位

    if (!pattern.test(userPhone)) {
      wx.showToast({
        title: '手机号码有误',
        duration: 1500,
        icon: 'none'
      });
      this.setData({
        userPhone: ''
      })
      return
    } else if (!pattern2.test(password)) {
      wx.showToast({
        title: '密码至少4位',
        duration: 1500,
        icon: 'none'
      });
      this.setData({
        password: ''
      })
      return
    } else if (password != userConfirmPasword || userConfirmPasword == '') {
      wx.showToast({
        title: '上下密码不一致',
        duration: 1500,
        icon: 'none',
      })
      this.setData({
        userConPuserConfirmPaswordassword: ''
      })
      return
    } else {
      wx.request({
        url: 'http://localhost/medical/user.php',
        method: 'GET',
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        data: {
          phone: e.detail.value.userPhone,
          pwd: e.detail.value.password,
        },
        success: function (res) {
          console.log(res)
        }
      })
      wx.showToast({
        title: '注册成功',
        duration: 3000,
        icon: 'success'
      });
      wx.navigateTo({
        url: '../login/login',
      })
    }
  },
  // checkPhone: function (e) {
  //   console.log(e)
  //   var userphone = e.detail.value
  //   console.log('userphone:' + userphone)
  //   this.setData({
  //     userPhone: userphone
  //   })
  // },
  // checkPassword: function (e) {
  //   var password = e.detail.value
  //   console.log('password:' + password)
  //   this.setData({
  //     password: password
  //   })
  // },
  // ConfirmPassword: function (e) {
  //   var userConfirmPasword = e.detail.value
  //   console.log('userConfirmPasword:' + userConfirmPasword)
  //   this.setData({
  //     userConfirmPasword: userConfirmPasword
  //   })
  // },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})